/**
 * Created by huotaol on 2017/6/28.
 */
import React, {Component} from "react";
import PropTypes from "prop-types";
import {Text, TouchableOpacity, View} from "react-native";
import {connect} from "react-redux";
import ModuleCommonHeader from "../../main/module/ModuleCommonHeader";
import Util from "../../main/Util";
import * as RequestUtil from "../../../common/util/RequestUtil";
import CustomStyle from "../../../common/style/CustomStyle";
import {setLoadingState} from "../../redux/action/homePage";
import * as Url from "../../constant/Url";

class ApplyLoan extends Component {
    static propTypes = {
        data: PropTypes.object.isRequired,
    };
    // 构造
    constructor(props) {
        super(props);
        // 初始状态
        this.state = {};
        console.log('ApplyLoan constructor    ' + JSON.stringify(this.props.data));
        this._apply = this._apply.bind(this);
    }

    render() {
        const {data} = this.props;
        return (
            <View style={{flex: 1}}>
                <ModuleCommonHeader title={'申请贷款'}/>
                <View style={{
                    flex: 1, paddingLeft: CustomStyle.getActualSizeInHorizontal(16),
                    paddingRight: CustomStyle.getActualSizeInHorizontal(16),
                }}>
                    <Text
                        style={[CustomStyle.baseText, {
                            fontSize: CustomStyle.getActualFontSize(30),
                            color: 'black',
                        }]}>买二手车做按揭，就选车行家</Text>
                    <Text
                        style={[CustomStyle.baseText, {
                            fontSize: CustomStyle.getActualFontSize(24),
                            color: 'black',
                        }]}>{CONTENT_1}</Text>
                    <Text
                        style={[CustomStyle.baseText, {
                            fontSize: CustomStyle.getActualFontSize(24),
                            color: 'black',
                        }]}>{CONTENT_2}</Text>
                    <Text
                        style={[CustomStyle.baseText, {
                            fontSize: CustomStyle.getActualFontSize(24),
                            color: 'black',
                        }]}>{CONTENT_3}</Text>
                </View>
                <TouchableOpacity style={{
                    height: CustomStyle.getActualSizeInVertical(88),
                    width: CustomStyle.getActualSizeInHorizontal(530),
                    backgroundColor: '#FF7200',
                    alignItems: 'center',
                    justifyContent: 'center',
                    marginTop: CustomStyle.getActualSizeInVertical(50),
                    marginBottom: CustomStyle.getActualSizeInVertical(30),
                    borderRadius: CustomStyle.getActualSizeInVertical(44),
                    alignSelf: 'center',
                }}
                                  onPress={() => {
                                      this._apply(data);
                                  }}
                >
                    <Text style={[CustomStyle.baseText, {
                        fontSize: CustomStyle.getActualFontSize(36),
                        color: 'white',
                    }]}>申请贷款</Text>
                </TouchableOpacity>

            </View>
        );
    }

    _apply(item) {
        this.props.setLoading(true, '提交中...');
        const url = Url.BASE_URL + '/finance/confirmloan';
        const param = new FormData();
        param.append('fid', item.id);
        RequestUtil.request(url, 'post', param).then(ret => {
            this.props.setLoading(false);
            const {status} = ret;
            if (status === 0) {
                Util.showToast('申请成功，请注意查收短信');
            }
        }).catch(err => {
            this.props.setLoading(false);
            Util.showToast(err);
        });
    }

}
const CONTENT_1 = `
优势：
可以一见倾心，不必一见倾“薪”：利率低至5厘8 ，绝对真实！
专业金融顾问一对一为您制定金融按揭方案：手续简单审批快，绝不产生其他任何费用
“贷”不走风险：过完户当天放款可提车（规避风险：为什么我们需要过完户才提车，因为要清楚车辆的前端违法状态必须是完成过户以后才能全清债权债务情况）
`;

const CONTENT_2 = `
畅行无忧：您不必面对：
未过户车辆上路风险
1．车辆原始违法记录（车辆被扣风险）
2．车辆原始债权抵押（车辆被金融公司收回的风险）
3．车辆债权不清晰（车辆交易合同普通老百姓不明了其中合同关系被不良车商钻空子，车辆交易后难扯皮）
`;

const CONTENT_3 = `
尽管车辆已经被使用且最后你还可以通过法律的途径进行维权，可是，你损失的绝不仅是时间。所以选择一家正规的二手车商很重要，选择一家正规的金融贷款渠道商更重要！
`;

const mapStateToProps = (state) => {
    const {userData} = state;
    return {
        userData: userData,
    };
};

const mapDispatchToProps = (dispatch) => {
    return {
        setLoading: (loading, text) => {
            dispatch(setLoadingState(loading, text));
        },
    };
};
export default connect(mapStateToProps, mapDispatchToProps)(ApplyLoan);
